<?php
namespace app\admin\controller;
use think\facade\Db;

use think\Controller;
use app\service\wotuService;
use app\service\visitorService;
use app\service\iotmcuService;
use think\facade\Log;

class Task extends Controller{
	public function test(){
		Log::write("测试","测试");
	}
	//访客到期时间30分钟
	public function visitordel(){
		//查询访客创建时间大于30分钟的
		$time=time()-6*60*60;
		$userlist=Db::table("visitor")
			->where("create_time","<",$time)
            ->where("state",1)
			->order("id desc")
			->select();
		Log::write($userlist,"定时删除访客");
		foreach ($userlist as $key => $userinfo) {

        	if($userinfo["personGuid"]!="0"){
                $result=(new wotuService())->del($userinfo["personGuid"]);
                if($result["code"]=="WO_SUS1000"){
                    Db::table("visitor")->where("id",$userinfo["id"])->update(["personGuid"=>"0"]);
                }
        	}
			Db::table("visitor")->where("id",$userinfo["id"])->update(["state"=>"2","del_time"=>date('Y-m-d H:i:s')]);
		}
	}



}